package com.relax.tmall;

public class Tmall {
    private int num;

    public synchronized void tack() throws InterruptedException {
        if (num >= 10) {
            System.out.println(Thread.currentThread().getName() + "数量太多,商家要停止生产");
            wait();
        }
        notifyAll();
        num++;
        System.out.println(Thread.currentThread().getName() + " 当前生产的数量:" + num);
    }

    public synchronized void sell() throws InterruptedException {
        if (num <= 0) {
            System.out.println(Thread.currentThread().getName() + "库存为空");
            wait();
        }
        notifyAll();
        num--;
        System.out.println(Thread.currentThread().getName() + " 当前库存:" + num);
    }
}
